﻿using System.Drawing;
using System.Windows.Forms;

namespace Marmat.Forms
{
    public class ContextMenuStripRenderer : ToolStripRenderer
    {
        public ContextMenuStripRenderer()
        {
            this.RenderItemText += ContextMenuStripRenderer_RenderItemText;
            this.RenderMenuItemBackground += ContextMenuStripRenderer_RenderMenuItemBackground;
        }

        private void ContextMenuStripRenderer_RenderItemText(object sender, ToolStripItemTextRenderEventArgs e)
        {
            e.TextColor = e.Item.Selected ? Color.White : Color.Black;
        }

        private void ContextMenuStripRenderer_RenderMenuItemBackground(object sender, ToolStripItemRenderEventArgs e)
        {
            e.Graphics.SetClip(new Rectangle(0, 0, e.Item.Width + 5, e.ToolStrip.Height));
            using var Brush = new SolidBrush(e.Item.Selected ? Color.FromArgb(52, 205, 98) : Color.White);
            e.Graphics.FillRectangle(Brush, e.Item.ContentRectangle);
        }
    }
}